from django.urls import path, include
from . import views
from .views import DoctorView, DepartmentListView
from rest_framework.routers import DefaultRouter
from .workflow_views import TaskSubmitView, TaskApproveView, TaskInfoView, AgentMonitorView

# 创建路由器并注册工作流视图集
router = DefaultRouter()
# 只保留确认存在的视图集
router.register(r'workflows', views.WorkflowViewSet, basename='workflow')
router.register(r'workflow-permissions', views.WorkflowPermissionViewSet, basename='workflow-permission')
router.register(r'positions', views.PositionViewSet, basename='position')
router.register(r'workflow-approval-nodes', views.WorkflowApprovalNodeViewSet, basename='workflow-approval-node')
router.register(r'tasks', views.TaskViewSet, basename='task')
router.register(r'audit-records', views.AuditRecordViewSet, basename='audit-record')

urlpatterns = [
    # 图片验证码
    path('image-code/', views.get_admin_image_code, name='admin_image_code'),
    
    # 短信验证码
    path('send-code/', views.send_admin_verification_code, name='admin_send_code'),
    
    # 登录
    path('login/', views.admin_login, name='admin_login'),
    
    # 退出登录
    path('logout/', views.admin_logout, name='admin_logout'),
    
    # 管理员信息
    path('info/', views.AdminInfoView.as_view(), name='admin_info'),
    
    # 管理员用户权限管理
    path('doctor-permission/', views.DoctorPermissionView.as_view(), name='doctor_permission'),
    path('doctor-permission/<int:doctor_id>/', views.DoctorPermissionView.as_view(), name='doctor_permission_detail'),
    
    # 获取角色列表
    path('roles/', views.RoleListView.as_view(), name='role_list'),
    
    # 获取资源列表
    path('resources/', views.ResourceListView.as_view(), name='resource_list'),
    
    # 医生管理
    path('doctors/', DoctorView.as_view(), name='doctor-list'),
    path('doctors/<int:doctor_id>/', DoctorView.as_view(), name='doctor-detail'),
    path('departments/', DepartmentListView.as_view(), name='department-list'),
    
    # 工作流相关路由 - 移到路由器注册之前
    path('workflow/dashboard/', views.WorkflowDashboardView.as_view(), name='workflow-dashboard'),
    path('workflow/<int:workflow_id>/form/', views.WorkflowFormView.as_view(), name='workflow-form'),
    path('task/<int:task_id>/approve/', views.TaskApprovalView.as_view(), name='task-approve'),
    path('task/<int:task_id>/detail/', views.TaskDetailView.as_view(), name='task-detail'),
    path('task/<int:task_id>/history/', views.TaskHistoryView.as_view(), name='task-history'),
    path('task/<int:task_id>/flow/', views.TaskFlowView.as_view(), name='task-flow'),
    path('my-tasks/', views.MyTasksView.as_view(), name='my-tasks'),
    path('user/audit-records/', views.UserAuditRecordsView.as_view(), name='user-audit-records'),
    
    # 工作流审批节点配置
    path('workflow/<int:workflow_id>/nodes/', views.WorkflowNodeConfigView.as_view(), name='workflow-nodes'),
    path('workflow/<int:workflow_id>/nodes/<int:node_id>/', views.WorkflowNodeConfigView.as_view(), name='workflow-node-detail'),
    
    # 系统设置
    path('system/setup/', views.SystemSetupView.as_view(), name='system-setup'),
    
    # 使用路由器注册的工作流管理路由
    path('', include(router.urls)),
    
    # 工作流API路由
    path('workflow/submit/', TaskSubmitView.as_view(), name='workflow_submit'),
    path('workflow/approve/', TaskApproveView.as_view(), name='workflow_approve'),
    path('workflow/task/<int:task_id>/', TaskInfoView.as_view(), name='workflow_task_info'),
    path('workflow/task/', TaskInfoView.as_view(), name='workflow_task_info_query'),
    path('workflow/monitor/', AgentMonitorView.as_view(), name='workflow_monitor'),
] 